<!--
  停车场车辆关联表添加页面
  User: zsj
  Date: 2020-02-27
-->
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >

<!-- BEGIN FORM-->
<div class="portlet light">
    <div class="portlet-title">
        <div class="caption">
            <span class="caption-subject font-red-sunglo bold uppercase">停车场默认收费规则</span>
            <span class="caption-helper">设置停车场默认收费规则</span>
        </div>
    </div>
    <div class="portlet-body form">
        <!-- BEGIN FORM-->
        <form action="#" class="form-horizontal" id="save-module1">
            <div class="form-body">
                        <input class="hide" th:value="${parkId}" id="parkId">
                <div class="portlet-body table-responsive">
                    <div class="table-scrollable">
                        <table
                                class="table table-bordered table-hover"
                                id="table_1">
                            <thead>
                            <tr>
                                <th class="table-checkbox">
                                    <label class="mt-checkbox mt-checkbox-single mt-checkbox-outline">
                                        <input type="checkbox" class="checkbox-all" title="全选"><span></span>
                                    </label>
                                </th>

                                <th>收费规则名称</th>
                                <th>收费规则类型</th>
                                <th>添加时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="data,iterStat:${roleList}">
                                <td class="center">
                                    <label class="mt-checkbox mt-checkbox-single mt-checkbox-outline">
                                        <input type="checkbox" class="checkbox-child"
                                               title="选择此条数据" th:value="${data['id']}"
                                               th:data-type="${data['type']}"><span></span>
                                    </label>
                                </td>
                                <!--<td th:title="${data['id']}" th:text="${#strings.abbreviate(data['id'],32)}"></td>-->
                                <td th:title="${data['name']}" th:text="${#strings.abbreviate(data['name'],32)}"></td>
                                <td th:title="${data['type']}" th:if="${#strings.abbreviate(data['type'],32)} eq 0" th:text="按次收费"></td>
                                <td th:title="${data['type']}" th:if="${#strings.abbreviate(data['type'],32)} eq 1" th:text="自定义分段收费"></td>
                                <td th:title="${data['type']}" th:if="${#strings.abbreviate(data['type'],32)} eq 2" th:text="自定义时段收费"></td>
                                <td th:title="${data['createTime']}" th:text="${#dates.format(data['createTime'],'yyyy-MM-dd HH:mm:ss')}"></td>
                                <td>
                                    <div class="btn-group btn-group-xs btn-group-solid">
                                        <button type="button"  th:data-id="${data['id']}" th:data-type="${data['type']}" class="btn btn-success " onclick="chargeDetail(this)"> 查看详情 </button>
                                        <button type="button"  th:if="${data['flag']} eq 0" th:data-id="${data['id']}" th:data-type="${data['type']}" class="btn btn-success " onclick="bindRule(this,0)"> 绑定 </button>
                                        <button type="button"  th:if="${data['flag']} eq 1" th:data-id="${data['id']}" th:data-type="${data['type']}" class="btn btn-danger" onclick="bindRule(this,1)"> 解绑 </button>
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>

            </div>

        </form>
        <!-- END FORM-->
    </div>
</div>

<script>

    function bindRule(obj,flag){
        var id = $(obj).data("id");
        var parkId = $("#parkId").val();
        var type = $(obj).data("type");
        tools.post("/park/saveDefaultRules", {"ruleId":id,"parkId":parkId,"type":type,"flag":flag}, function (data) {
            if(data.success){
                layer.msg('设置成功！', {icon: 1,time:1000},function(){
                    toPage(null);
                    //跳转到第一页
                    layer.close(layer_defaultRules);
                });
            }else{
                tools.errorTip(data);
            }
        });

    }

    //收费规则详情
    function chargeDetail(obj) {
        var type = $(obj).data("type");
        var id = $(obj).data("id");
        tools.loadPage("/park/chargeDetail", {"id":id,"type":type}, function(html){
            window.layer_infoModule = layer.open({
                id:"infoModule",
                type: 1,
                title:"收费规则详情",
                /* area:['900px','600px'],*/
                area:'900px',
                content: html,
                anim:1,
                shadeClose:false,
                cancel: function(){}
            });
        });
    }

</script>
</html>